# -*- coding: utf-8 -*-
'''
Created on 2011-3-9

@author: Tony

根据用户名或者用户id获取用户的详细信息
'''
import unittest
from goplay.weibopy.auth import OAuthHandler
from goplay.weibopy.api import API

class getUser(unittest.TestCase):
    
    consumer_key= "3482834712"
    consumer_secret ="40c54f7f6730f543aed36b36f92ca06e"
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception, e:
            print e
            return ''
        
    def getAttValue(self, obj, key):
        try:
            return obj.__getattribute__(key)
        except Exception, e:
            print e
            return ''
    def setToken(self, token, tokenSecret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setToken(token, tokenSecret)
        self.api = API(self.auth)
        
    def userInfo(self,username):
        #myself = self.api.get_user(id=userid)
        myself = self.api.get_user(screen_name=username)
        self.obj = myself
        user={}
        user['profile_image'] = self.getAtt('profile_image_url')
        user['name']=self.getAtt("screen_name")
        user['description']=self.getAtt("description")
        user['city']=self.getAtt('city')
        user['province']=self.getAtt('province')
        user['location']=self.getAtt('location')
        user['gender']=self.getAtt('gender')
        #use = auth.get_username()
        return user
    
    def getUserInfo(self,username,token,tokenSecret):
        gu=getUser()
        gu.setToken(token,tokenSecret)
        userinfo=gu.userInfo(username)
        return userinfo

